<template>
  <div class="dashboard-editor-container">
    <div class="all-title">数据看板</div>
    <el-row :gutter="40" class="panel-group">
      <el-col class="card-panel-col">
        <div class="card-panel" @click="gotoapge('/order/service')">
          <div class="card-panel-description">
            <div class="card-panel-text">订单数</div>
            <div class="card-panel-num">{{ statistical.deliverOrder }}</div>
          </div>
          <div class="card-panel-icon-wrapper icon-message">
            <img src="../../assets/1.png" alt="" />
          </div>
        </div>
      </el-col>
      <el-col class="card-panel-col">
        <div class="card-panel" @click="gotoapge('/order/service')">
          <div class="card-panel-description">
            <div class="card-panel-text">成交金额</div>
            <div class="card-panel-num">{{ statistical.order_paytotal }}</div>
          </div>
          <div class="card-panel-icon-wrapper icon-message">
            <img src="../../assets/2.png" alt="" />
          </div>
        </div>
      </el-col>
      <el-col class="card-panel-col">
        <div class="card-panel" @click="gotoapge('/orderrefund/index')">
          <div class="card-panel-description">
            <div class="card-panel-text">售后订单</div>
            <div class="card-panel-num">{{ statistical.returnOrder }}</div>
          </div>

          <div class="card-panel-icon-wrapper icon-message">
            <img src="../../assets/3.png" alt="" />
          </div>
        </div>
      </el-col>
      <el-col class="card-panel-col">
        <div class="card-panel" @click="gotoapge('/member/index')">
          <div class="card-panel-description">
            <div class="card-panel-text">会员数</div>
            <div class="card-panel-num">{{ statistical.member_count }}</div>
          </div>

          <div class="card-panel-icon-wrapper icon-message">
            <img src="../../assets/4.png" alt="" />
          </div>
        </div>
      </el-col>
      <el-col v-if="version == 'v3'" class="card-panel-col">
        <div class="card-panel" @click="gotoapge('/technical/index')">
          <div class="card-panel-description">
            <div class="card-panel-text">师傅数</div>
            <div class="card-panel-num">{{ statistical.technical_count }}</div>
          </div>
          <div class="card-panel-icon-wrapper icon-message">
            <img src="../../assets/5.png" alt="" />
          </div>
        </div>
      </el-col>
      <el-col v-else class="card-panel-col">
        <div class="card-panel" @click="gotoapge('/agent/index')">
          <div class="card-panel-description">
            <div class="card-panel-text">分销达人数</div>
            <div class="card-panel-num">{{ statistical.agent_count }}</div>
          </div>

          <div class="card-panel-icon-wrapper icon-message">
            <img src="../../assets/5.png" alt="" />
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="40" class="second-group">
      <el-col class="sales-top-item">
        <div class="title">
          <div class="name">销量排行TOP5</div>
          <div class="unit">单位：次</div>
        </div>
        <div class="content">
          <div
            class="content-item"
            v-for="(item, index) in goodssaletop5"
            :key="index"
          >
            <div class="content-name">{{ item.name }}</div>
            <div
              class="content-bar"
              :style="{ width: item.sale_count * 50 + '%' }"
            ></div>
            <div class="content-text">{{ item.sale_count }}</div>
          </div>
        </div>
      </el-col>

      <el-col class="sales-top-item shifu" v-if="version == 'v3'">
        <div class="title">
          <div class="name">师傅服务排行TOP5</div>
          <div class="unit">单位：次</div>
        </div>
        <div class="content">
          <div
            class="content-item"
            v-for="(item, index) in service_timestop5"
            :key="index"
          >
            <div class="content-text">{{ item.service_times }}</div>
            <div
              class="content-bar"
              :style="{ height: item.service_times * 10 + '%' }"
            ></div>

            <div class="content-name">{{ item.title }}</div>
          </div>
        </div>
      </el-col>

      <el-col class="sales-top-item" v-else>
        <div class="title">
          <div class="name">会员付款排行TOP5</div>
          <div class="unit">单位：次</div>
        </div>
        <div class="content">
          <div
            class="content-item"
            v-for="(item, index) in consumedop5"
            :key="index"
          >
            <div class="content-name">{{ item.nickname }}</div>
            <div
              class="content-bar"
              :style="{ width: item.totleconsumed * 50 + '%' }"
            ></div>
            <div class="content-text">{{ item.totleconsumed }}</div>
          </div>
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="40" class="third-group">
      <el-col class="last">
        <div class="bottom_itemBox">
          <div class="flex_bbox">
            <div class="rank_title">昨天转化</div>
          </div>
          <div class="content">
            <div
              style="width: 200px; height: 200px"
              class="content-item"
              ref="dom1"
            ></div>
            <div
              style="width: 200px; height: 200px"
              class="content-item"
              ref="dom2"
            ></div>
            <div
              style="width: 200px; height: 200px"
              class="content-item"
              ref="dom3"
            ></div>
          </div>
          <!-- <div
            :style="
              'background: url(' +
              require('@/assets/data.png') +
              ') no-repeat top;'
            "
            class="databox_show-right"
          >
            <div class="title-list">
              <div class="li">访问人数</div>
              <div class="li">下单人数</div>
              <div class="li">支付订单数</div>
            </div>
            <div class="part1">
              <div>访问-支付</div>
              <span>转化率 {{ statistical.accessTopay_conversionrate }}%</span>
            </div>
            <div class="part2">
              <div>访问-下单</div>
              <span
                >转化率 {{ statistical.accessToorder_conversionrate }}%</span
              >
            </div>
            <div class="part3">
              <div>下单-支付</div>
              <span>转化率 {{ statistical.orderTopay_conversionrate }}%</span>
            </div>
          </div> -->
        </div>
      </el-col>
      <div class="chart">
        <line-chart :chart-data="lineChartData" />
      </div>
    </el-row>
  </div>
</template>

<script>
import LineChart from "./components/LineChart";
import PieChart from "./components/PieChart";
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
export default {
  name: "Dashboard",
  components: {
    LineChart,
    PieChart,
  },
  data() {
    return {
      version: "",
      lineChartData: {
        actualData: [0, 0, 0, 0, 0, 0, 0],
      },
      statistical: {},
      goodssaletop5: {},
      consumedop5: {},
      service_timestop5: {},
      chart: null,
      chart2: null,
      chart3: null,
    };
  },
  mounted() {
    this.$api.post("/Dashboard/index").then((res) => {
      this.version = res.data.version;
      this.statistical = res.data.statistical;
      this.goodssaletop5 = res.data.goodssaletop5;
      this.consumedop5 = res.data.consumedop5;
      this.service_timestop5 = res.data.service_timestop5;
      this.lineChartData.actualData = res.data.clinchadeal;
    });
    this.$api.get("/Dashboard/datainitial");
    this.$nextTick(() => {
      this.initChart();
    });
  },
  methods: {
    gotoapge(page) {
      this.$router.push({ path: page });
    },
    initChart() {
      this.chart = echarts.init(this.$refs.dom1, "macarons");
      this.chart2 = echarts.init(this.$refs.dom2, "macarons");
      this.chart3 = echarts.init(this.$refs.dom3, "macarons");
      this.chart.setOption({
        color: ["#CCC6C6", "#527AF3"],
        title: {
          show: true, //显示策略，默认值true,可选为：true（显示） | false（隐藏）
          text: "访问-支付", //主标题文本，'\n'指定换行
          x: "center", //水平安放位置，默认为'left'，可选为：'center' | 'left' | 'right' | {number}（x坐标，单位px）
          y: "bottom",
          textStyle: {
            color: "#3F3838",
          },
        },
        series: [
          {
            name: "访问-下单",
            type: "pie",
            radius: [15, 50],
            center: ["50%", "50%"],
            data: [
              {
                value: 320,
                name: "Industries",
                labelLine: { normal: { show: false } },
                label: { normal: { show: false } },
              },
              {
                value: 240,
                name: "Technology",
                labelLine: { normal: { show: false } },
                label: { normal: { show: false } },
              },
            ],
          },
        ],
      });
      this.chart2.setOption({
        title: {
          show: true, //显示策略，默认值true,可选为：true（显示） | false（隐藏）
          text: "下单-支付", //主标题文本，'\n'指定换行
          x: "center", //水平安放位置，默认为'left'，可选为：'center' | 'left' | 'right' | {number}（x坐标，单位px）
          y: "bottom",
          textStyle: {
            color: "#3F3838",
          },
        },
        color: ["#CCC6C6", "#527AF3"],
        series: [
          {
            name: "访问-支付",
            type: "pie",
            radius: [15, 50],
            center: ["50%", "50%"],
            data: [
              {
                value: 320,
                name: "Industries",
                labelLine: { normal: { show: false } },
                label: { normal: { show: false } },
              },
              {
                value: 240,
                name: "Technology",
                labelLine: { normal: { show: false } },
                label: { normal: { show: false } },
              },
            ],
          },
        ],
      });
      this.chart3.setOption({
        title: {
          show: true, //显示策略，默认值true,可选为：true（显示） | false（隐藏）
          text: "访问-支付", //主标题文本，'\n'指定换行
          x: "center", //水平安放位置，默认为'left'，可选为：'center' | 'left' | 'right' | {number}（x坐标，单位px）
          y: "bottom",
          textStyle: {
            color: "#3F3838",
          },
        },
        color: ["#CCC6C6", "#527AF3"],
        series: [
          {
            name: "访问-支付",
            type: "pie",
            radius: [15, 50],
            center: ["50%", "50%"],
            data: [
              {
                value: 320,
                name: "Industries",
                labelLine: { normal: { show: false } },
                label: { normal: { show: false } },
              },
              {
                value: 240,
                name: "Technology",
                labelLine: { normal: { show: false } },
                label: { normal: { show: false } },
              },
            ],
          },
        ],
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
  .all-title {
    font-size: 30px;
    color: #212226;
    margin-bottom: 28px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
.second-group::before,
.second-group::after {
  display: none;
}
.second-group {
  background: transparent;
  margin: 0;
  display: flex;
  justify-content: space-between;
  margin-left: 0 !important;
  margin-right: 0 !important;
  margin-bottom: 20px;
  .sales-top-item.shifu {
    .content {
      display: flex;
      justify-content: space-between;
      height: 86%;
      .content-item {
        width: 100px;
        height: 100%;
        flex-direction: column;
        justify-content: flex-end;
        .content-name {
          width: 100px;
          font-size: 18px;
          text-align: center;
        }
        .content-bar {
          width: 28px;
          background: #389fef;
          margin: 20px 0;
        }
      }
    }
  }
  .sales-top-item {
    width: 48%;
    background: #fff;
    box-sizing: border-box;
    padding: 30px;
    color: #3f3838;
    border-radius: 8px;
    .title {
      display: flex;
      justify-content: space-between;
      .name {
        font-size: 22px;
      }
    }
    .content {
      .content-item {
        display: flex;
        align-items: center;
        margin-top: 20px;
        .content-name {
          width: 150px;
          text-align: right;
          font-size: 18px;
        }
        .content-bar {
          height: 28px;
          background: #389fef;
          margin: 0 20px;
        }
      }
    }
  }
}
.panel-group {
  background: #fff;
  width: 100%;
  margin-left: 0 !important;
  margin-right: 0 !important;
  margin-bottom: 20px;
  border-radius: 10px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  .card-panel-col {
    // margin-bottom: 32px;
    width: 18%;
    border-radius: 8px;
    padding: 20px 10px;
    box-sizing: border-box;
  }
  .card-panel-col:nth-child(1) {
    background: #389fef;
  }
  .card-panel-col:nth-child(2) {
    background: #527af3;
  }
  .card-panel-col:nth-child(3) {
    background: #489eff;
  }
  .card-panel-col:nth-child(4) {
    background: #8f7fff;
  }
  .card-panel-col:nth-child(5) {
    background: #45c1cc;
  }

  .card-panel {
    height: 108px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 8px;
    // background: #fff;
    // box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    // border-color: rgba(0, 0, 0, .05);
    color: #fff;
    img {
      width: 50px;
      height: 50px;
    }
    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }

      .icon-themaster {
        background: #36a3f7;
      }
      .icon-tree {
        background: #36a3f7;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .icon-themaster {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      .card-panel-text {
        line-height: 18px;
        color: #fff;
        font-size: 20px;
        line-height: 40px;
      }

      .card-panel-num {
        font-size: 60px;

        text-align: left;
      }
    }
  }
}
.third-group::after,
.third-group::before {
  display: none;
}
.third-group {
  display: flex;
  justify-content: space-between;
  margin-left: 0 !important;
  margin-right: 0 !important;
  .last {
    width: 48%;
    padding: 0 !important;
    .rank_title {
      color: #3f3838;
      font-size: 22px;
      font-weight: 500;
    }
    .content {
      display: flex;
      justify-content: space-between;
      margin-top: 20px;
    }
  }
  .chart {
    width: 48%;
    background: #fff;
    .chart {
      height: calc(100% - 50px) !important;
    }
    .title {
      color: #3f3838;
      font-size: 22px;
      font-weight: 500;
      padding: 20px;
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

/* 底部三格列表 */
.flex_bbox {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
}

.leftBottom_box.flex_bbox {
  align-items: flex-start;
}

.bottom_itemBox {
  min-height: 352px;
  background: #ffffff;
  border-radius: 10px;
  box-sizing: border-box;
  padding: 30px;
  overflow: hidden;
}

.rank_title {
  color: #232323;
  font-size: 20px;
  font-weight: bold;
}

select.rank_select {
  font-size: 16px;
  color: #999999;
  border: 0;
  width: 58px;
  cursor: pointer;
}

table.rank_tableBox {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.rank_tableBox thead tr {
  font-size: 16px;
  color: #333333;
  border-bottom: 1px solid #f0f0f0;
  text-align: left;
  height: 58px;
}

.rank_tableBox tbody tr td {
  padding-top: 20px;
  font-size: 16px;
  color: #333333;
}

.rank_tableBox tbody tr td.rank_tbody_td {
  color: #999999;
  width: 65%;
  word-break: break-all;
}

.databox_show-right {
  position: relative;
  margin-left: auto;
  margin-right: auto;
  margin-top: 60px;
  height: 162px;
}

.databox_show-right .title-list {
  display: block;
  text-align: center;
}

.databox_show-right .title-list .li {
  display: block;
  text-align: center;
  font-size: 14px;
  color: #fff;
  line-height: 47px;
}

.databox_show-right .part1 {
  position: absolute;
  top: 60px;
  left: 7px;
  text-align: center;
}

.databox_show-right .part2 {
  position: absolute;
  top: 33px;
  right: 20px;
  text-align: center;
}

.databox_show-right .part3 {
  position: absolute;
  top: 90px;
  right: 33px;
  text-align: center;
}

.databox_show-right span {
  color: #666;
  font-size: 12px;
}

.databox-ranking .content-ranking {
  min-height: 200px;
}
</style>
